package com.mengxuegu.member.controller;

import com.mengxuegu.member.base.Result;
import com.mengxuegu.member.entity.Staff;
import com.mengxuegu.member.req.PasswordREQ;
import com.mengxuegu.member.service.IStaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class AuthController {

    @Autowired
    IStaffService staffService;

    /**
     * 校验原密码是否正确
     * @param req 要检查的密码和用户id
     * @return 正确与否
     */
    @PostMapping("/pwd")
    public Result checkPwd(@RequestBody PasswordREQ req) {
        return staffService.checkPassword(req);
    }

    /**
     * 提交修改密码
     * @param req 要修改的密码和用户id
     * @return 成功与否
     */
    @PutMapping("/pwd")
    public Result updatePwd(@RequestBody PasswordREQ req) {
        return staffService.updatePassword(req);
    }

    @PostMapping("/login")
    public Result login(@RequestBody  Staff staff) {
        return staffService.login(staff.getUsername(), staff.getPassword());
    }

    /**
     * 通过token获取用户信息
     * @param token
     * @return
     */
    @GetMapping("/info")
    public Result getUserInfo(@RequestParam String token) {
        System.out.println(token);
        return staffService.getUserInfo(token);
    }

    @PostMapping("/logout")
    public Result logout() {
        return Result.ok();
    }

}
